/******************************************************/
/***************** 数据库操作相关处理 *****************/
/******************************************************/

const { getFormStandardFields, getBaeTableStandardCols, getBaseCrudStandardFieldsAndCols } = require("./core/compile/vue");
const { crateCrudModule, createFormFile, createTableFile, createModulesByMenus } = require("./core/creator/vue");
const navs = require("./core/creator/vue/_temp/navs");
const { letDataToJsFile } = require("./core/creator/vue/_utils");
const { writeFileSync } = require("./core/utils");

// 文件写入到 app/tables-data.js
// const { getStandTablesData } = require("./core/compile/mysql");
// getStandTablesData("/app/tables-data.js");

// 测试写入demo文件
// const { writeFileSync } = require("./core/utils");
// const { letDataToJsFile } = require("./core/creator/vue/_utils");

// const obj = {
//   name: "John Doe",
//   age: 30,
//   isMale: true,
// };

// writeFileSync("/demo/test.js", letDataToJsFile(obj, "exports.data ="));

// 测试写入vue模块文件
const queryFields = [
  { prop: "yhid", label: "用户ID" },
  {
    prop: "ffzt",
    label: "发放状态",
    type: "select",
    attrs: {
      options: "D_YesNoStatus",
    },
  },
  { prop: "czr", label: "操作人" },
  { prop: "bz", label: "备注" },
  { prop: "ffsj", label: "发放时间", type: "date-picker" },
];
const tableCols = [
  {
    prop: "ffcgyhid",
    label: "发放成功用户ID",
    minWidth: 210,
  },
  {
    prop: "ffsbyhid",
    label: "发放失败用户ID",
    minWidth: 210,
  },
  {
    prop: "ffje",
    label: "发放金额",
    minWidth: 90,
  },
  {
    prop: "ffzt",
    label: "发放状态",
    type: "BaseTag",
    attrs: {
      name: "SendStatus",
    },
  },
  { prop: "ffsj", label: "发放时间" },
  { prop: "imtz", label: "IM通知", minWidth: 190 },
  { prop: "bz", label: "备注", minWidth: 140 },
  { prop: "updated", label: "操作人", type: "update" },
];
const addEditFields = [
  {
    prop: "ffdx",
    label: "发放对象",
    required: true,
    attrs: {
      type: "textarea",
    },
    quickAttrs: {
      tips: "多个用户用，分隔",
    },
  },
  {
    prop: "ffje",
    label: "发放金额",
    required: true,
    type: "input-number",
  },
  {
    prop: "imtz",
    label: "IM通知",
    attrs: {
      type: "textarea",
    },
  },
  {
    prop: "bz",
    label: "备注",
    required: true,
    attrs: {
      type: "textarea",
    },
  },
];
// crateCrudModule("/demo/vue/user", { queryFields, tableCols, addEditFields });

// 创建表单、表格文件示例
// const rows = [
//   { id: 1, zy: "大家看到", xb: "男" },
//   { id: 2, zy: "大家看到", xb: "男" },
//   { id: 3, zy: "大家看到", xb: "男" },
//   { id: 4, zy: "大家看到", xb: "男" },
// ];
// createFormFile(`/demo/vue/user/DemoForm.vue`, queryFields);
// createTableFile(`/demo/vue/user/DemoTable.vue`, tableCols, rows);

const simpleQueryFormFields = ["remark", "enableStatus:status", { tpl: "phone" }];
const simpleCommonFormFields = ["remark", "enableStatus:status", { tpl: "phone" }];
const simpleCrudTableCols = ["remark", "enableStatus:status"];
const commonFormFields = getFormStandardFields(simpleCommonFormFields);
const queryFormFields = getFormStandardFields(simpleCommonFormFields, "query");
const baseTablCols = getBaeTableStandardCols(simpleCrudTableCols);
const crudFieldsAndCols = getBaseCrudStandardFieldsAndCols(simpleQueryFormFields, simpleCrudTableCols);

// writeFileSync(`/demo/data/form.js`, letDataToJsFile(commonFormFields, "exports.fields ="));
// writeFileSync(`/demo/data/table.js`, letDataToJsFile(baseTablCols, "exports.cols ="));
// writeFileSync(`/demo/data/crud.js`, letDataToJsFile(crudFieldsAndCols, "exports.data ="));

// crateCrudModule("/demo/vue/user", { queryFields: queryFormFields, tableCols: baseTablCols, addEditFields: commonFormFields });
// createFormFile(`/demo/vue/user/DemoForm.vue`, commonFormFields);
// createTableFile(`/demo/vue/user/DemoTable.vue`, baseTablCols, []);

createModulesByMenus(`/demo/menus`, navs, { queryFields: queryFormFields, tableCols: baseTablCols, addEditFields: commonFormFields });
